// 列表带输入框 的组件

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../share/my_color.dart';
import '../../share/my_font.dart';
import '../../share/size_fill.dart';

//看完注释文字提示
// 一列里面 有输入框的widget， 比如 个人中心 修改昵称  左边是 title  右边是 输入框 的
//title 和 输入框后面的 默认是不展示的
//可以通过 修改 输入框的对齐方式 修改 输入框在左边还是在右边开始的
class ShowTitleInputListWidget extends StatelessWidget {
  String? title; //标题
  TextStyle? titleStyle;
  EdgeInsetsGeometry? padding;
  Widget? icon;
  final bool showBottomLine; //是否展示线条
  final Color lineColor;
  EdgeInsetsGeometry? linePadding;
  EdgeInsetsGeometry contentPadding;

  final TextInputType keyboardType; //键盘样式
  InputDecoration? inputDecoration; //设置输入框样式
  final bool obscureText; //密码输入样式

  String placeholder;
  TextStyle? placeholderStyle;
  TextStyle? inputStyle;
  ValueChanged? inputTextTapChange;
  int? maxLength;
  final TextEditingController? controller;
  int maxLine;
  int minLine;

  final TextAlign textAlign;
  double? textFieldHeight;
  final FocusNode? focusNode;
  final TextInputAction textInputAction;
  final VoidCallback? onEditingComplete;

  final titleWidget;

  ShowTitleInputListWidget({
    this.onEditingComplete,
    this.contentPadding = const EdgeInsets.symmetric(vertical: 0),
    this.titleWidget,
    this.title,
    this.titleStyle,
    this.padding,
    this.obscureText = false,
    this.placeholder = "话题名称 (必填)", //输入框提示
    this.placeholderStyle, //默认提示字体样式
    this.inputStyle, //输入字体样式
    this.inputTextTapChange, //输入字体回调
    this.icon, //右边 widget
    this.showBottomLine = true, //是否显示线条
    this.lineColor = MyColors.color_238_238_238, //线条颜色
    this.linePadding, //底部线条padding
    this.keyboardType = TextInputType.text, //键盘样式
    this.inputDecoration, //输入框颜色，比如边框 背景颜色 圆角 等
    this.maxLength, //输入框最大输入数
    this.controller, // 输入框控制器
    this.textAlign: TextAlign.right, //输入框文本 对齐方式
    this.textFieldHeight, //输入框高度默认48*px
    this.focusNode, //输入框焦点
    this.textInputAction = TextInputAction.done,
    this.maxLine = 1,
    this.minLine = 1,
  });

  @override
  Widget build(BuildContext context) {
    if (textFieldHeight == null) {
      textFieldHeight = SizeFill.setRx(48);
    }
    if (titleStyle == null) {
      titleStyle = TextStyle(color: MyColors.color_51_51_51, fontSize: MyFont.font16);
    }
    if (inputStyle == null) {
      inputStyle = TextStyle(color: MyColors.color_51_51_51, fontSize: MyFont.font16);
    }
    if (placeholderStyle == null) {
      placeholderStyle = TextStyle(color: MyColors.color_221_221_221, fontSize: MyFont.font16);
    }
    if (padding == null) {
      padding = EdgeInsets.symmetric(vertical: SizeFill.setRx(0), horizontal: SizeFill.setRx(15));
    }
    if (linePadding == null) {
      linePadding = EdgeInsets.symmetric(horizontal: SizeFill.setRx(15));
    }
    if (maxLength == null) {
      maxLength = 0x7fffffff;
    }

    if (inputDecoration == null) {
      inputDecoration = InputDecoration(
        hintText: placeholder,
        hintStyle: placeholderStyle,
        counterText: "",
        contentPadding:contentPadding,
        fillColor: MyColors.color_255_255_255,
        border: OutlineInputBorder(
//          borderRadius: BorderRadius.circular(SizeFill.setRx(5)),//设置边框
          borderSide: BorderSide.none,
        ),
        //不需要边框线条
        filled: true,
      );
    }

    Widget? titleWidget;
    if (this.titleWidget != null) {
      titleWidget = this.titleWidget;
    } else {
      if (this.title == null) {
        titleWidget = Container();
      } else {
        titleWidget = Row(
          children: [
            Text(title!, style: titleStyle),
            SizedBox(
              width: SizeFill.setRx(10),
            ),
          ],
        );
      }
    }

    if (icon == null) {
      icon = Container();
    }

    Widget bottomLineWidget;
    if (showBottomLine) {
      bottomLineWidget = Padding(
        padding: linePadding!,
        child: Divider(
          height: 1,
          color: lineColor,
        ),
      );
    } else {
      bottomLineWidget = Container();
    }
    Widget textField = Container(
      child: TextField(
        maxLines: this.maxLine,
        obscureText: obscureText,
        focusNode: focusNode,
        minLines: this.minLine,
        style: inputStyle,
        textInputAction: textInputAction,
        decoration: inputDecoration,
        maxLength: maxLength,
        keyboardType: keyboardType,
        maxLengthEnforced: true,
        textAlign: textAlign,
        onChanged: inputTextTapChange,
        controller: controller,
        onEditingComplete: onEditingComplete,
      ),
      height: textFieldHeight,
    );

    // TODO: implement build
    return Column(
      children: [
        Container(
          padding: padding,
          child: Row(
            children: [
              titleWidget!,
              Expanded(child: textField),
              icon!,
            ],
          ),
        ),
        GestureDetector(child: bottomLineWidget),
      ],
    );
  }
}
